package com.situ.firmadmin.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.situ.firmadmin.constants.RedisConstants;
import com.situ.firmadmin.mapper.ReimMapper;
import com.situ.firmadmin.pojo.Reim;
import com.situ.firmadmin.pojo.User;
import com.situ.firmadmin.pojo.query.ReimQuery;
import com.situ.firmadmin.pojo.vo.DeptReimVO;
import com.situ.firmadmin.pojo.vo.TypeCountVO;
import com.situ.firmadmin.pojo.vo.UserReimVO;
import com.situ.firmadmin.service.IReimService;
import com.situ.firmadmin.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ReimServiceImpl implements IReimService {
    @Autowired
    private ReimMapper reimMapper;
    @Autowired
    private RedisTemplate redisTemplate;


    @Override
    public PageResult selectByPage(ReimQuery reimQuery, User user) {
        PageHelper.startPage(reimQuery.getPage(), reimQuery.getLimit());
        List<UserReimVO> list=reimMapper.selectByPage(reimQuery,user);
        PageInfo<UserReimVO> pageInfo=new PageInfo<>(list);
        int total=(int)pageInfo.getTotal();
        return new PageResult(0,"",total,list);
    }

    @Override
    public void insert(Reim reim) {
        reimMapper.insert(reim);
        redisTemplate.opsForSet().add(RedisConstants.UPLOAD_IMAGE_TO_DB, reim.getImage());
    }

    @Override
    public void updateDelete(Integer id,User user) {
        reimMapper.updateDelete(id,user);
    }

    @Override
    public void updateDeleteAll(Integer[] ids) {
        reimMapper.updateDeleteAll(ids);
    }

    @Override
    public void deleteById(Integer id) {
        reimMapper.deleteById(id);
    }

    @Override
    public UserReimVO selectById(Integer id) {
        return reimMapper.selectById(id);
    }

    @Override
    public void update(Reim reim) {
        reimMapper.update(reim);
        redisTemplate.opsForSet().add(RedisConstants.UPLOAD_IMAGE_TO_DB, reim.getImage());

    }

    @Override
    public PageResult selectByUserId(User user,ReimQuery reimQuery) {
        PageHelper.startPage(reimQuery.getPage(), reimQuery.getLimit());
        List<UserReimVO> list=reimMapper.selectByUserId(user,reimQuery);
        PageInfo<UserReimVO> pageInfo=new PageInfo<>(list);
        int total=(int)pageInfo.getTotal();
        return new PageResult(0,"",total,list);
    }

    @Override
    public PageResult selectByAdminId(ReimQuery reimQuery,User user) {
        PageHelper.startPage(reimQuery.getPage(), reimQuery.getLimit());
        List<UserReimVO> list=reimMapper.selectByAdminId(reimQuery,user);
        PageInfo<UserReimVO> pageInfo=new PageInfo<>(list);
        int total=(int)pageInfo.getTotal();
        return new PageResult(0,"",total,list);
    }

    @Override
    public void updateAudit(Reim reim) {
        reimMapper.updateAudit(reim);
    }
    
    @Override
    public List<DeptReimVO> selectByMonth(Integer dId) {
        return reimMapper.selectByMonth(dId);
    }
    
    @Override
    public Long selectAdopt() {
        return reimMapper.selectAdopt();
    }
    
    @Override
    public Long selectAllAmount() {
        return reimMapper.selectAllAmount();
    }
    
}
